package example

import (
	"io/ioutil"
	"net/http"
	"time"
)

const defaultTimeout = 3 * time.Second

// CallHTTPRequest 调用 HTTP 请求
func CallHTTPRequest() ([]byte, error) {
	client := http.Client{
		Timeout: defaultTimeout,
	}

	req, err := http.NewRequest(http.MethodGet, "localhost:8000/test", nil)
	if err != nil {
		return nil, err
	}

	rsp, err := client.Do(req)
	if err != nil {
		return nil, err
	}

	defer rsp.Body.Close()

	return ioutil.ReadAll(rsp.Body)
}
